<template>
	<view class="list">
		<view v-for="(item,index) in list" @click="goDetail(item.villager_id)">
			<view class="li">
				<view class="">
					<text>{{item.createtime}}</text>
				</view>
				<view class="list_body">
					<view class="list_content">
						<text>{{item.name}}</text>
					</view>
					<view class="edit-wrapper">
						<text v-if="item.type==0">
							暂无
						</text>
						<text v-else-if="item.type==1">
							电访
						</text>
						<text v-else-if="item.type==2">
							面访
						</text>
						<text class="edit" @click.stop="edit(item.id,item.villager_id)">编辑</text>
					</view>
				</view>
			</view>
		</view>
		<view class="loadingText">{{loadingText}}</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				page: 1,
				loadingText: '',
				time_type: 0,
				status: 0,
				type: 0
			}
		},
		onPullDownRefresh() {
			this.page = 1
			this.getList();
		},
		onReachBottom() {
			this.loadingText = "上拉显示更多"
			this.getMoreList();
		},
		onShow() {

			this.list = [];
			this.page = 1;
			this.getList();
		},
		onLoad(option) {
			this.time_type = option.type;
		},
		methods: {
			getMoreList() {
				this.loadingText = '-- 正在加载 --'
				let obj = {};
				obj.page = this.page;
				obj.time_type = this.time_type;
				obj.status = this.status;
				obj.type = this.type;
				this.$api.post('/api/villagers/visitList', obj).then(res => {
					if (res.code == 1) {
						this.info = res.data;
						if (res.data.list.length == 0 || res.data.list == null) {
							this.loadingText = '-- 暂无更多 --'
							return false;
						}
						var newlist = res.data.list;
						this.list = this.list.concat(newlist)
						this.page++
					} else {
						this.toastMsg(res.msg);
					}
				});
			},

			getList() {
				console.log(666)
				let obj = {};
				obj.page = this.page;
				obj.time_type = this.time_type;
				obj.status = this.status;
				obj.type = this.type;
				this.$api.post('/api/villagers/visitList', obj).then((res) => {
					if (res.code == 1) {
						if (res.data.list.length == 0 || res.data.list == null) {
							this.loadingText = '-- 暂无更多 --'
							return false;
						}
						this.list = res.data.list;
						uni.stopPullDownRefresh()
						this.page++
					} else {
						this.toastMsg(res.msg);
					}
				})
			},
			edit(id,villager_id){
				uni.navigateTo({
					url:'../index/visit-edit?id='+id+'&villager_id='+villager_id
				})
			},
			goDetail(id){
				uni.navigateTo({
					url:'../index/visit-detail?id='+id
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #EFF1F5;
	}
</style>
<style lang="scss">
	.loadingText {
		padding: 20rpx 0 40rpx 0;
		text-align: center;
		color: #310D05;
		font-size: 28rpx;
	}

	.list {

		padding: 30rpx;

		.li {
			margin-top: 30rpx;

		}
	}

	.list_body {
		background-color: #fff;
		margin: 20rpx 20rpx 20rpx 0;
		padding: 30rpx;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
        color: #333333;
		.list_content {

			text {
				color: #333333;
				font-size: 32rpx;
			}

			
		}
		.edit-wrapper{
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			text {
				color: #666;
				font-size: 28rpx;
			}
			.edit{
				padding-top: 20rpx;
				color: #333333;
				font-size: 28rpx;
			}
		}
	}
</style>
